package com.chb.demo.service;

import com.chb.demo.dao.ArtistDao;
import com.chb.demo.dao.CompanyDao;
import com.chb.demo.dao.StyleDao;
import com.chb.demo.entity.Artist;
import com.chb.demo.entity.Company;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompanyService {
    @Autowired
    CompanyDao companyDao;
    @Autowired
    ArtistDao artistDao;
    @Autowired
    StyleDao styleDao;

    public Page<Company> findAllCompany(int pageNo, int pageSize) {
        PageRequest pageRequest = PageRequest.of((pageNo - 1) * pageSize, pageSize);
        System.out.println(pageRequest.toString());
        return  companyDao.findAll(pageRequest);
    }

    public List<Artist> findCompanyArtist(String companyname, String style, String masterpiece) {
        Integer cid = null;
        Integer sid = null;
        try {
            cid = companyDao.findByDisplayname(companyname).getCid();
        }catch (Exception e){
            System.out.println("没有公司名");
        }
        try {
            sid = styleDao.findByDescription(style).getSid();
        }catch (Exception e){
            System.out.println("没有风格名");
        }

        List<Artist> list = artistDao.searchArtist(
                cid,
                sid,
                masterpiece);
        return list;
    }
}
